/**
 * Copyright (C) 2009 aileron.cc
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package cc.aileron.orm;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

import org.junit.Test;
import org.junit.runner.RunWith;

import cc.aileron.generic.Id;
import cc.aileron.generic.Paging;
import cc.aileron.junit.runner.guice.GuiceInjectRunner;
import cc.aileron.junit.runner.guice.GuiceInjectRunnerModule;
import cc.aileron.orm.sample.SampleEntity;
import cc.aileron.orm.util.G2DaoCondition;

import com.google.inject.Inject;

/**
 * とりあえず、試してみる
 * 
 * @author Aileron
 */
@GuiceInjectRunnerModule(TryModule.class)
@RunWith(GuiceInjectRunner.class)
public class TryOrm
{

    /**
     * try create
     */
    @Test
    public void spec()
    {
        for (int i = 1, max = 100; i < max; i++)
        {
            final SampleEntity entity = new SampleEntity();
            entity.id = new Id(10);
            entity.content = "test";
            dao.from(SampleEntity.class)
                .insert(entity);
        }

        final Paging paging = new Paging(50);
        paging.page = 0;
        assertThat(dao.from(SampleEntity.class)
            .find(G2DaoCondition.All)
            .list(new Paging(50, 0))
            .size(), is(50));

        paging.page = 1;
        assertThat(dao.from(SampleEntity.class)
            .find(G2DaoCondition.All)
            .list(paging)
            .size(), is(50));

        paging.page = 2;
        assertThat(dao.from(SampleEntity.class)
            .find(G2DaoCondition.All)
            .list(paging)
            .size(), is(0));

        dao.from(SampleEntity.class)
            .find(G2DaoCondition.All)
            .one();
    }

    /**
     * @param dao
     */
    @Inject
    public TryOrm(final G2DaoManager dao)
    {
        this.dao = dao;
    }

    /**
     * dao
     */
    private final G2DaoManager dao;
}